#!/bin/bash

# 设置变量
mkdir -p output

NAME="youdu_ima"

OUTPUT_FILE="../output/install_$NAME.exe"

# 更新 install.sh 脚本
cp ./bash/install.sh ./packer/dist/install.sh
chmod +x ./packer/dist/install.sh
# 复制 sso 证书
mkdir -p ./packer/dist/ssl/sso
cp ./src/ssl/sso/* ./packer/dist/ssl/sso/

cd packer
# 清除旧的编译文件
rm -f $OUTPUT_FILE
# 根据参数判断编译平台：w、l、la、m
if [ "$1" == "w" ]; then
    GOOS=windows GOARCH=amd64 go build -o $OUTPUT_FILE
elif [ "$1" == "l" ]; then
    GOOS=linux GOARCH=amd64 go build -o $OUTPUT_FILE
    chmod +x $OUTPUT_FILE
    if [ "$2" == "u" ]; then
        # 上传到服务器
        scp $OUTPUT_FILE root@121.229.102.17:~/youdu_service/
        # 远程执行安装程序
        ssh root@121.229.102.17 "~/youdu_service/install_$NAME.exe"
    fi
elif [ "$1" == "la" ]; then
    GOOS=linux GOARCH=arm64 go build -o $OUTPUT_FILE
elif [ "$1" == "m" ]; then
    GOOS=darwin GOARCH=amd64 go build -o $OUTPUT_FILE
else
    echo "Usage: $0 {w|l|la|m}"
    # echo "w: Windows 64-bit"
    # echo "l: Linux 64-bit"
    # echo "la: Linux ARM 64-bit"
    # echo "m: macOS 64-bit"
    # echo "Example: $0 w"
    # echo "Example: $0 l"
    # echo "Example: $0 la"
    # echo "Example: $0 m"
    exit 1
fi
echo "打包完成，输出文件在 $OUTPUT_FILE"

